#!/bin/bash

#=======================================================================
# git-listbundle
# File ID: 8ae2b66c-fcd1-11e0-a4c9-65862771f905
# List all heads that the required heads of a bundle are members of.
# License: GNU General Public License version 2 or later.
#=======================================================================

progname=git-listbundle
bundle=$1
grepfilter=

listbundle() {
    for f in $(LC_ALL=C git bundle verify $bundle | grep -$1 9999999 "^The bundle requires these" | grep -E "^[0-9a-f]{40} " | cut -f 1 -d ' '); do
        git log -1 --format="=== %H%n   %d%n    %s" $f | cat
        if test -n "$grepfilter"; then
            git lc $f | grep $grepfilter;
        else
            git lc $f
        fi
    done
}

test -z "$bundle" && { echo "Syntax: $progname bundlefile [grepfilter [...]]"; exit 1; }
if test -n "$2"; then
    shift
    for f in $*; do
        grepfilter="$grepfilter -e $f"
    done
fi
echo ======== Included refs:
listbundle B
echo
echo ======== Required refs:
listbundle A
